package com.timoon.webcomponent.utility.navs.red;

import java.util.List;

import org.apache.wicket.AttributeModifier;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.image.Image;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.apache.wicket.request.resource.CssResourceReference;
import org.apache.wicket.request.resource.JavaScriptResourceReference;
import org.apache.wicket.request.resource.PackageResourceReference;

import com.googlecode.wicket.jquery.ui.JQueryBehavior;
import com.googlecode.wicket.jquery.ui.Options;
import com.timoon.component.behavior.bootstrap.AbstractBootStrapBehavior;
import com.timoon.webcomponent.utility.navs.BaseNavPanel;
import com.timoon.webcomponent.utility.navs.NavParameter;

/**
 *<p></p>
 *<p></p>
 *<p>Copyright:Copyright(c)2013.4.1</p>
 *<p>Company:timoon</p>
 *@author 付乐天
 *@version 1.0 */
public class RedNavPanel extends BaseNavPanel {

	private static String SELECTED_KEY="ewiruwern324320895kjlwfe";
	
	private int menuCount=1;
	private int childMenuCount=1;
	
	public RedNavPanel(String id, List<NavParameter> navs,PageParameters pageParameter) {
		super(id, navs);
		// TODO Auto-generated constructor stub
		add(new RedNavBehavior("#fefwe4534534","click"));
		//引用bootstrap
		this.add(new AbstractBootStrapBehavior("#ddddddd", "click", new Options()));
		
		final String selectedKey=pageParameter.get(SELECTED_KEY).toString("default");
		
		ListView<NavParameter> listView=new ListView<NavParameter>("wk_li",navs) {
			
			@Override
			protected void populateItem(ListItem<NavParameter> arg0) {
				// TODO Auto-generated method stub
				NavParameter p=arg0.getModelObject();
				
				arg0.add(new AttributeModifier("id","m_"+menuCount));
				arg0.add(new AttributeModifier("onmouseover","mover("+menuCount+");"));
				arg0.add(new AttributeModifier("onmouseout","mout("+menuCount+");"));
				
				if(menuCount==1){
					arg0.add(new AttributeModifier("class","m_li_a"));
				}else{
					arg0.add(new AttributeModifier("class","m_li"));
				}
				
				PageParameters pp=new PageParameters();
				pp.set(SELECTED_KEY, p.getKey());
				BookmarkablePageLink link=new BookmarkablePageLink<>("wk_a", p.getTargetPage(),pp);
				arg0.add(link);
				link.add(new Label("wk_span",p.getText()));
				
				menuCount++;
			}
		};
		add(listView);
		
		ListView<NavParameter> childListView=new ListView<NavParameter>("wk_child_li",navs) {

			@Override
			protected void populateItem(ListItem<NavParameter> arg0) {
				// TODO Auto-generated method stub
				NavParameter p=arg0.getModelObject();
				
				arg0.add(new AttributeModifier("id","s_"+childMenuCount));
				arg0.add(new AttributeModifier("onmouseover","mover("+childMenuCount+");"));
				arg0.add(new AttributeModifier("onmouseout","mout("+childMenuCount+");"));
				
				if(childMenuCount==1){
					arg0.add(new AttributeModifier("class","s_li_a"));
				}else{
					arg0.add(new AttributeModifier("class","s_li"));
				}
				
				ListView<NavParameter> childAListView=new ListView<NavParameter>("wk_child_loop",p.getChilds()) {

					@Override
					protected void populateItem(ListItem<NavParameter> arg0) {
						// TODO Auto-generated method stub
						NavParameter p=arg0.getModelObject();
						
						BookmarkablePageLink link=new BookmarkablePageLink<>("wk_child_a", p.getTargetPage());
						arg0.add(link);
						
						link.add(new Label("wk_child_span",p.getText()));
					}
				};
				arg0.add(childAListView);
				
				childMenuCount++;
			}
		};
		add(childListView);
	}

}
class RedNavBehavior extends JQueryBehavior{

	public RedNavBehavior(String selector,String method) {
		super(selector,method);
		// TODO Auto-generated constructor stub
		this.add(new CssResourceReference(this.getClass(), "css.css"));
	}
	
}
